home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as.sun3 / RCS / write.c,v < prev   
Encoding:
Text File  |  1991-10-18  |  35.9 KB  |  1,225 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    rab:1.1; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     91.10.18.16.10.57;  author rab;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* write.c - emit .o file - Copyright(C)1986 Free Software Foundation, Inc.
  26.    Copyright (C) 1986,1987 Free Software Foundation, Inc.
  27.  
  28. This file is part of GAS, the GNU Assembler.
  29.  
  30. GAS is free software; you can redistribute it and/or modify
  31. it under the terms of the GNU General Public License as published by
  32. the Free Software Foundation; either version 1, or (at your option)
  33. any later version.
  34.  
  35. GAS is distributed in the hope that it will be useful,
  36. but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38. GNU General Public License for more details.
  39.  
  40. You should have received a copy of the GNU General Public License
  41. along with GAS; see the file COPYING.  If not, write to
  42. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  43.  
  44. /* 
  45.  
  46.    Umm, with real good luck, this thing should be set up to do byteordering
  47.    correctly, but I may have managed to miss a place or two.  Treat a.out
  48.    very carefully until you're SURE that it works. . .
  49.  
  50.    In order to cross-assemble the target machine must have an a.out header
  51.    similar to the one in a.out.h on THIS machine.  Byteorder doesn't matter;
  52.    we take special care of it, but the numbers must be the same SIZE (# of
  53.    bytes) and in the same PLACE.  If this is not true, you will have some
  54.    trouble.
  55.  */
  56.  
  57. #include "as.h"
  58. #include "md.h"
  59. #include "subsegs.h"
  60. #include "obstack.h"
  61. #include "struc-symbol.h"
  62. #include "write.h"
  63. #include "symbols.h"
  64.  
  65. #ifdef SPARC
  66. #include "sparc.h"
  67. #endif
  68.  
  69. void    append();
  70.  
  71. #ifdef hpux
  72. #define EXEC_MACHINE_TYPE HP9000S200_ID
  73. #endif
  74.  
  75. /*
  76.  * In: length of relocation (or of address) in chars: 1, 2 or 4.
  77.  * Out: GNU LD relocation length code: 0, 1, or 2.
  78.  */
  79.  
  80. static unsigned char
  81.  
  82. nbytes_r_length [] = {
  83.   42, 0, 1, 42, 2
  84.   };
  85.  
  86.  
  87. static struct frag *    text_frag_root;
  88. static struct frag *    data_frag_root;
  89.  
  90. static struct frag *    text_last_frag;    /* Last frag in segment. */
  91. static struct frag *    data_last_frag;    /* Last frag in segment. */
  92.  
  93. static struct exec    the_exec;
  94.  
  95. static long int string_byte_count;
  96.  
  97. static char *        the_object_file;
  98.  
  99. #ifndef SPARC
  100. static
  101. #endif
  102. char *        next_object_file_charP;    /* Tracks object file bytes. */
  103.  
  104. static long int        size_of_the_object_file; /* # bytes in object file. */
  105.  
  106. /* static long int        length; JF unused */    /* String length, including trailing '\0'. */
  107.  
  108. static void    relax_segment();
  109. void        emit_segment();
  110. static relax_addressT    relax_align();
  111. static long int    fixup_segment();
  112. #ifndef SPARC
  113. static void        emit_relocations();
  114. #endif
  115. /*
  116.  *            fix_new()
  117.  *
  118.  * Create a fixS in obstack 'notes'.
  119.  */
  120. void
  121. #ifdef SPARC
  122. fix_new (frag, where, size, add_symbol, sub_symbol, offset, pcrel, r_type)
  123. #else
  124. fix_new (frag, where, size, add_symbol, sub_symbol, offset, pcrel)
  125. #endif
  126.      fragS *    frag;        /* Which frag? */
  127.      int    where;        /* Where in that frag? */
  128.      short int    size;        /* 1, 2  or 4 usually. */
  129.      symbolS *    add_symbol;    /* X_add_symbol. */
  130.      symbolS *    sub_symbol;    /* X_subtract_symbol. */
  131.      long int    offset;        /* X_add_number. */
  132.      int    pcrel;        /* TRUE if PC-relative relocation. */
  133. #ifdef SPARC
  134.     int        r_type;
  135. #endif
  136. {
  137.   register fixS *    fixP;
  138.  
  139.   fixP = (fixS *)obstack_alloc(¬es,sizeof(fixS));
  140.  
  141.   fixP -> fx_frag    = frag;
  142.   fixP -> fx_where    = where;
  143.   fixP -> fx_size    = size;
  144.   fixP -> fx_addsy    = add_symbol;
  145.   fixP -> fx_subsy    = sub_symbol;
  146.   fixP -> fx_offset    = offset;
  147.   fixP -> fx_pcrel    = pcrel;
  148.   fixP -> fx_next    = * seg_fix_rootP;
  149.  
  150.   /* JF these 'cuz of the NS32K stuff */
  151.   fixP -> fx_im_disp    = 0;
  152.   fixP -> fx_pcrel_adjust = 0;
  153.   fixP -> fx_bsr    = 0;
  154.   fixP ->fx_bit_fixP    = 0;
  155.  
  156. #ifdef SPARC
  157.   fixP->fx_r_type = r_type;
  158. #endif
  159.  
  160.   * seg_fix_rootP = fixP;
  161. }
  162.  
  163. void
  164. write_object_file()
  165. {
  166.   register struct frchain *    frchainP; /* Track along all frchains. */
  167.   register fragS *        fragP;    /* Track along all frags. */
  168.   register struct frchain *    next_frchainP;
  169.   register fragS * *        prev_fragPP;
  170.   register char *        name;
  171.   register symbolS *        symbolP;
  172.   register symbolS **        symbolPP;
  173.   /* register fixS *        fixP; JF unused */
  174.   unsigned
  175.       text_siz,
  176.     data_siz,
  177.     syms_siz,
  178.     tr_siz,
  179.     dr_siz;
  180.   void output_file_create();
  181.   void output_file_append();
  182.   void output_file_close();
  183.   void gdb_emit();
  184.   void gdb_end();
  185.   extern long omagic;        /* JF magic # to write out.  Is different for
  186.                    Suns and Vaxen and other boxes */
  187.  
  188. #ifdef    VMS
  189.   /*
  190.    *    Under VMS we try to be compatible with VAX-11 "C".  Thus, we
  191.    *    call a routine to check for the definition of the procedure
  192.    *    "_main", and if so -- fix it up so that it can be program
  193.    *    entry point.
  194.    */
  195.   VMS_Check_For_Main();
  196. #endif /* VMS */
  197.   /*
  198.    * After every sub-segment, we fake an ".align ...". This conforms to BSD4.2
  199.    * brane-damage. We then fake ".fill 0" because that is the kind of frag
  200.    * that requires least thought. ".align" frags like to have a following
  201.    * frag since that makes calculating their intended length trivial.
  202.    */
  203. #define SUB_SEGMENT_ALIGN (2)
  204.   for ( frchainP=frchain_root; frchainP; frchainP=frchainP->frch_next )
  205.     {
  206. #ifdef    VMS
  207.       /*
  208.        *    Under VAX/VMS, the linker (and PSECT specifications)
  209.        *    take care of correctly aligning the segments.
  210.        *    Doing the alignment here (on initialized data) can
  211.        *    mess up the calculation of global data PSECT sizes.
  212.        */
  213. #undef    SUB_SEGMENT_ALIGN
  214. #define    SUB_SEGMENT_ALIGN ((frchainP->frch_seg != SEG_DATA) ? 2 : 0)
  215. #endif    /* VMS */
  216.       subseg_new (frchainP -> frch_seg, frchainP -> frch_subseg);
  217.       frag_align (SUB_SEGMENT_ALIGN, 0);
  218.                 /* frag_align will have left a new frag. */
  219.                 /* Use this last frag for an empty ".fill". */
  220.       /*
  221.        * For this segment ...
  222.        * Create a last frag. Do not leave a "being filled in frag".
  223.        */
  224.       frag_wane (frag_now);
  225.       frag_now -> fr_fix    = 0;
  226.       know( frag_now -> fr_next == NULL );
  227.       /* know( frags . obstack_c_base == frags . obstack_c_next_free ); */
  228.       /* Above shows we haven't left a half-completed object on obstack. */
  229.     }
  230.  
  231.   /*
  232.    * From now on, we don't care about sub-segments.
  233.    * Build one frag chain for each segment. Linked thru fr_next.
  234.    * We know that there is at least 1 text frchain & at least 1 data frchain.
  235.    */
  236.   prev_fragPP = &text_frag_root;
  237.   for ( frchainP=frchain_root; frchainP; frchainP=next_frchainP )
  238.     {
  239.       know( frchainP -> frch_root );
  240.       * prev_fragPP = frchainP -> frch_root;
  241.       prev_fragPP = & frchainP -> frch_last -> fr_next;
  242.       if (   ((next_frchainP = frchainP->frch_next) == NULL)
  243.       || next_frchainP == data0_frchainP)
  244.     {
  245.       prev_fragPP = & data_frag_root;
  246.       if ( next_frchainP )
  247.         {
  248.           text_last_frag = frchainP -> frch_last;
  249.         }
  250.       else
  251.         {
  252.           data_last_frag = frchainP -> frch_last;
  253.         }
  254.     }
  255.     }                /* for(each struct frchain) */
  256.  
  257.   /*
  258.    * We have two segments. If user gave -R flag, then we must put the
  259.    * data frags into the text segment. Do this before relaxing so
  260.    * we know to take advantage of -R and make shorter addresses.
  261.    */
  262.   if ( flagseen [ 'R' ] )
  263.     {
  264.       fixS *tmp;
  265.  
  266.       text_last_frag -> fr_next = data_frag_root;
  267.       text_last_frag = data_last_frag;
  268.       data_last_frag = NULL;
  269.       data_frag_root = NULL;
  270.       if(text_fix_root) {
  271.     for(tmp=text_fix_root;tmp->fx_next;tmp=tmp->fx_next)
  272.       ;
  273.     tmp->fx_next=data_fix_root;
  274.       } else
  275.         text_fix_root=data_fix_root;
  276.       data_fix_root=NULL;
  277.     }
  278.  
  279.   relax_segment (text_frag_root, SEG_TEXT);
  280.   relax_segment (data_frag_root, SEG_DATA);
  281.   /*
  282.    * Now the addresses of frags are correct within the segment.
  283.    */
  284.  
  285.   know(   text_last_frag -> fr_type   == rs_fill && text_last_frag -> fr_offset == 0 );
  286.   text_siz=text_last_frag->fr_address;
  287. #ifdef SPARC
  288.   text_siz= (text_siz+7)&(~7);
  289.   text_last_frag->fr_address=text_siz;
  290. #endif
  291.   md_number_to_chars((char *)&the_exec.a_text,text_siz, sizeof(the_exec.a_text));
  292.   /* the_exec . a_text = text_last_frag -> fr_address; */
  293.  
  294.   /*
  295.    * Join the 2 segments into 1 huge segment.
  296.    * To do this, re-compute every rn_address in the SEG_DATA frags.
  297.    * Then join the data frags after the text frags.
  298.    *
  299.    * Determine a_data [length of data segment].
  300.    */
  301.   if (data_frag_root)
  302.     {
  303.       register relax_addressT    slide;
  304.  
  305.       know(   text_last_frag -> fr_type   == rs_fill && text_last_frag -> fr_offset == 0 );
  306.       data_siz=data_last_frag->fr_address;
  307. #ifdef SPARC
  308.       data_siz += (8 - (data_siz % 8)) % 8;
  309.       data_last_frag->fr_address = data_siz;
  310. #endif
  311.       md_number_to_chars((char *)&the_exec.a_data,data_siz,sizeof(the_exec.a_data));
  312.       /* the_exec . a_data = data_last_frag -> fr_address; */
  313.       slide = text_siz; /* Address in file of the data segment. */
  314.       for (fragP = data_frag_root;
  315.        fragP;
  316.        fragP = fragP -> fr_next)
  317.     {
  318.       fragP -> fr_address += slide;
  319.     }
  320.       know( text_last_frag );
  321.       text_last_frag -> fr_next = data_frag_root;
  322.     }
  323.   else {
  324.       md_number_to_chars((char *)&the_exec.a_data,0,sizeof(the_exec.a_data));
  325.       data_siz = 0;
  326.   }
  327.  
  328.   bss_address_frag . fr_address = text_siz + data_siz;
  329. #ifdef SPARC
  330.   local_bss_counter=(local_bss_counter+7)&(~7);
  331. #endif
  332.   md_number_to_chars((char *)&the_exec.a_bss,local_bss_counter,sizeof(the_exec.a_bss));
  333.  
  334.           
  335.   /*
  336.    *
  337.    * Crawl the symbol chain.
  338.    *
  339.    * For each symbol whose value depends on a frag, take the address of
  340.    * that frag and subsume it into the value of the symbol.
  341.    * After this, there is just one way to lookup a symbol value.
  342.    * Values are left in their final state for object file emission.
  343.    * We adjust the values of 'L' local symbols, even if we do
  344.    * not intend to emit them to the object file, because their values
  345.    * are needed for fix-ups.
  346.    *
  347.    * Unless we saw a -L flag, remove all symbols that begin with 'L'
  348.    * from the symbol chain.
  349.    *
  350.    * Count the (length of the nlists of the) (remaining) symbols.
  351.    * Assign a symbol number to each symbol.
  352.    * Count the number of string-table chars we will emit.
  353.    *
  354.    */
  355.   know( zero_address_frag . fr_address == 0 );
  356.   string_byte_count = sizeof( string_byte_count );
  357.  
  358.   /* JF deal with forward references first. . . */
  359.   for(symbolP=symbol_rootP;symbolP;symbolP=symbolP->sy_next) {
  360.       if(symbolP->sy_forward) {
  361.         symbolP->sy_value+=symbolP->sy_forward->sy_value+symbolP->sy_forward->sy_frag->fr_address;
  362.         symbolP->sy_forward=0;
  363.     }
  364.   }
  365.   symbolPP = & symbol_rootP;    /* -> last symbol chain link. */
  366.   {
  367.     register long int        symbol_number;
  368.  
  369.     symbol_number = 0;
  370.     while (symbolP  = * symbolPP)
  371.       {
  372.     name = symbolP -> sy_name;
  373.     if(flagseen['R'] && (symbolP->sy_nlist.n_type&N_DATA)) {
  374.       symbolP->sy_nlist.n_type&= ~N_DATA;
  375.       symbolP->sy_nlist.n_type|= N_TEXT;
  376.     }
  377.     /* if(symbolP->sy_forward) {
  378.       symbolP->sy_value += symbolP->sy_forward->sy_value + symbolP->sy_forward->sy_frag->fr_address;
  379.     } */
  380.     
  381.     symbolP -> sy_value += symbolP -> sy_frag -> fr_address;
  382.         /* JF the 128 bit is a hack so stabs like
  383.            "LET_STMT:23. . ."  don't go away */
  384.     /* CPH: 128 bit hack is moby loser.  N_SO for file "Lower.c"
  385.        fell through the cracks.  I think that N_STAB should be
  386.        used instead of 128. */
  387.         /* JF the \001 bit is to make sure that local labels
  388.            ( 1: - 9: don't make it into the symtable either */
  389. #ifndef    VMS    /* Under VMS we need to keep local symbols */
  390.     if ( !name || (symbolP->sy_nlist.n_type&N_STAB)
  391.         || (name[0]!='\001' && (flagseen ['L'] || name [0] != 'L' )))
  392. #endif    /* not VMS */
  393.       {
  394.         symbolP -> sy_number = symbol_number ++;
  395. #ifndef    VMS
  396.         if (name)
  397.           {            /* Ordinary case. */
  398.         symbolP -> sy_name_offset = string_byte_count;
  399.         string_byte_count += strlen (symbolP  -> sy_name) + 1;
  400.           }
  401.         else            /* .Stabd case. */
  402. #endif    /* not VMS */
  403.         symbolP -> sy_name_offset = 0;
  404.         symbolPP = & (symbolP -> sy_next);
  405.       }
  406. #ifndef    VMS
  407.     else
  408.         * symbolPP = symbolP -> sy_next;
  409. #endif    /* not VMS */
  410.       }                /* for each symbol */
  411.  
  412.     syms_siz = sizeof( struct nlist) * symbol_number;
  413.     md_number_to_chars((char *)&the_exec.a_syms,syms_siz,sizeof(the_exec.a_syms));
  414.     /* the_exec . a_syms = sizeof( struct nlist) * symbol_number; */
  415.   }
  416.  
  417.   /*
  418.    * Addresses of frags now reflect addresses we use in the object file.
  419.    * Symbol values are correct.
  420.    * Scan the frags, converting any ".org"s and ".align"s to ".fill"s.
  421.    * Also converting any machine-dependent frags using md_convert_frag();
  422.    */
  423.   subseg_change( SEG_TEXT, 0);
  424.  
  425.   for (fragP = text_frag_root;  fragP;  fragP = fragP -> fr_next)
  426.     {
  427.       switch (fragP -> fr_type)
  428.     {
  429.     case rs_align:
  430.     case rs_org:
  431.       fragP -> fr_type = rs_fill;
  432.       know( fragP -> fr_var == 1 );
  433.       know( fragP -> fr_next );
  434.       fragP -> fr_offset
  435.         =     fragP -> fr_next -> fr_address
  436.           -   fragP -> fr_address
  437.         - fragP -> fr_fix;
  438.       break;
  439.  
  440.     case rs_fill:
  441.       break;
  442.  
  443.     case rs_machine_dependent:
  444.       md_convert_frag (fragP);
  445.       /*
  446.        * After md_convert_frag, we make the frag into a ".space 0".
  447.        * Md_convert_frag() should set up any fixSs and constants
  448.        * required.
  449.        */
  450.       frag_wane (fragP);
  451.       break;
  452.  
  453. #ifndef WORKING_DOT_WORD
  454.     case rs_broken_word:
  455.       {
  456.         struct broken_word *lie;
  457.         extern md_short_jump_size;
  458.         extern md_long_jump_size;
  459.  
  460.         if(fragP->fr_subtype) {
  461.           fragP->fr_fix+=md_short_jump_size;
  462.           for(lie=(struct broken_word *)(fragP->fr_symbol);lie && lie->dispfrag==fragP;lie=lie->next_broken_word)
  463.         if(lie->added==1)
  464.           fragP->fr_fix+=md_long_jump_size;
  465.         }
  466.         frag_wane(fragP);
  467.       }
  468.       break;
  469. #endif
  470.  
  471.     default:
  472.       BAD_CASE( fragP -> fr_type );
  473.       break;
  474.     }            /* switch (fr_type) */
  475.     }                /* for each frag. */
  476.  
  477. #ifndef WORKING_DOT_WORD
  478.     {
  479.       struct broken_word *lie;
  480.       struct broken_word **prevP;
  481.  
  482.       prevP= &broken_words;
  483.       for(lie=broken_words; lie; lie=lie->next_broken_word)
  484.     if(!lie->added) {
  485. #ifdef SPARC
  486.       fix_new(    lie->frag,  lie->word_goes_here - lie->frag->fr_literal,
  487.               2,  lie->add,
  488.             lie->sub,  lie->addnum,
  489.             0,  NO_RELOC);
  490. #endif
  491. #ifdef NS32K
  492.       fix_new_ns32k(lie->frag,
  493.               lie->word_goes_here - lie->frag->fr_literal,
  494.             2,
  495.             lie->add,
  496.             lie->sub,
  497.             lie->addnum,
  498.             0, 2, 0, 0);
  499. #endif
  500. #if !defined(SPARC) && !defined(NS32K)
  501.       fix_new(    lie->frag,  lie->word_goes_here - lie->frag->fr_literal,
  502.               2,  lie->add,
  503.             lie->sub,  lie->addnum,
  504.             0);
  505. #endif
  506.       /* md_number_to_chars(lie->word_goes_here,
  507.                    lie->add->sy_value
  508.                    + lie->addnum
  509.                    - (lie->sub->sy_value),
  510.                  2); */
  511.       *prevP=lie->next_broken_word;
  512.     } else
  513.       prevP= &(lie->next_broken_word);
  514.  
  515.       for(lie=broken_words;lie;) {
  516.     struct broken_word *untruth;
  517.     char    *table_ptr;
  518.     long    table_addr;
  519.     long    from_addr,
  520.         to_addr;
  521.     int    n,
  522.         m;
  523.  
  524.     extern    md_short_jump_size;
  525.     extern    md_long_jump_size;
  526.     void    md_create_short_jump();
  527.     void    md_create_long_jump();
  528.  
  529.  
  530.  
  531.     fragP=lie->dispfrag;
  532.  
  533.     /* Find out how many broken_words go here */
  534.     n=0;
  535.     for(untruth=lie;untruth && untruth->dispfrag==fragP;untruth=untruth->next_broken_word)
  536.       if(untruth->added==1)
  537.         n++;
  538.  
  539.     table_ptr=lie->dispfrag->fr_opcode;
  540.     table_addr=lie->dispfrag->fr_address+(table_ptr - lie->dispfrag->fr_literal);
  541.     /* Create the jump around the long jumps */
  542.     /* This is a short jump from table_ptr+0 to table_ptr+n*long_jump_size */
  543.     from_addr=table_addr;
  544.     to_addr = table_addr + md_short_jump_size + n * md_long_jump_size;
  545.     md_create_short_jump(table_ptr,from_addr,to_addr,lie->dispfrag,lie->add);
  546.     table_ptr+=md_short_jump_size;
  547.     table_addr+=md_short_jump_size;
  548.  
  549.     for(m=0;lie && lie->dispfrag==fragP;m++,lie=lie->next_broken_word) {
  550.       if(lie->added==2)
  551.         continue;
  552.       /* Patch the jump table */
  553.       /* This is the offset from ??? to table_ptr+0 */
  554.       to_addr =   table_addr
  555.                 - (lie->sub->sy_value);
  556.       md_number_to_chars(lie->word_goes_here,to_addr,2);
  557.       for(untruth=lie->next_broken_word;untruth && untruth->dispfrag==fragP;untruth=untruth->next_broken_word) {
  558.         if(untruth->use_jump==lie)
  559.           md_number_to_chars(untruth->word_goes_here,to_addr,2);
  560.       }
  561.  
  562.       /* Install the long jump */
  563.       /* this is a long jump from table_ptr+0 to the final target */
  564.       from_addr=table_addr;
  565.       to_addr=lie->add->sy_value+lie->addnum;
  566.       md_create_long_jump(table_ptr,from_addr,to_addr,lie->dispfrag,lie->add);
  567.       table_ptr+=md_long_jump_size;
  568.       table_addr+=md_long_jump_size;
  569.     }
  570.       }
  571.     }
  572. #endif
  573. #ifndef    VMS
  574.   /*
  575.    * Scan every FixS performing fixups. We had to wait until now to do
  576.    * this because md_convert_frag() may have made some fixSs.
  577.    */
  578.   /* the_exec . a_trsize
  579.     = sizeof(struct relocation_info) * fixup_segment (text_fix_root, N_TEXT);
  580.   the_exec . a_drsize
  581.     = sizeof(struct relocation_info) * fixup_segment (data_fix_root, N_DATA); */
  582.  
  583.   tr_siz=sizeof(struct relocation_info) * fixup_segment (text_fix_root, N_TEXT);
  584.   md_number_to_chars((char *)&the_exec.a_trsize, tr_siz ,sizeof(the_exec.a_trsize));
  585.   dr_siz=sizeof(struct relocation_info) * fixup_segment (data_fix_root, N_DATA);
  586.   md_number_to_chars((char *)&the_exec.a_drsize, dr_siz, sizeof(the_exec.a_drsize));
  587. #ifdef EXEC_MACHINE_TYPE
  588.   md_number_to_chars((char *)&the_exec.a_machtype, EXEC_MACHINE_TYPE, sizeof(the_exec.a_machtype));
  589. #endif
  590.  
  591.   md_number_to_chars((char *)&the_exec.a_magic,omagic,sizeof(the_exec.a_magic));
  592.   md_number_to_chars((char *)&the_exec.a_entry,0,sizeof(the_exec.a_entry));
  593.   /* the_exec . a_entry = 0; */
  594.  
  595.   size_of_the_object_file =
  596.     sizeof( the_exec ) +
  597.       text_siz +
  598.         data_siz +
  599.       syms_siz +
  600.         tr_siz +
  601.           dr_siz +
  602.         string_byte_count;
  603.     
  604.   next_object_file_charP
  605.     = the_object_file
  606.       = xmalloc ( size_of_the_object_file );
  607.  
  608.   output_file_create (out_file_name);
  609.  
  610.   append (& next_object_file_charP, (char *)(&the_exec), (unsigned long)sizeof(the_exec));
  611.  
  612.   /*
  613.    * Emit code.
  614.    */
  615.   for (fragP = text_frag_root;  fragP;  fragP = fragP -> fr_next)
  616.     {
  617.       register long int        count;
  618.       register char *        fill_literal;
  619.       register long int        fill_size;
  620.  
  621.       know( fragP -> fr_type == rs_fill );
  622.       append (& next_object_file_charP, fragP -> fr_literal, (unsigned long)fragP -> fr_fix);
  623.       fill_literal= fragP -> fr_literal + fragP -> fr_fix;
  624.       fill_size   = fragP -> fr_var;
  625.       know( fragP -> fr_offset >= 0 );
  626.       for (count = fragP -> fr_offset;  count;  count --)
  627.       append (& next_object_file_charP, fill_literal, (unsigned long)fill_size);
  628.     }                /* for each code frag. */
  629.  
  630.   /*
  631.    * Emit relocations.
  632.    */
  633.   emit_relocations (text_fix_root, (relax_addressT)0);
  634.   emit_relocations (data_fix_root, text_last_frag -> fr_address);
  635.   /*
  636.    * Emit all symbols left in the symbol chain.
  637.    * Any symbol still undefined is made N_EXT.
  638.    */
  639.   for (   symbolP = symbol_rootP;   symbolP;   symbolP = symbolP -> sy_next   )
  640.     {
  641.       register char *    temp;
  642.  
  643.       temp = symbolP -> sy_nlist . n_un . n_name;
  644.       /* JF fix the numbers up. Call by value RULES! */
  645.       md_number_to_chars((char *)&(symbolP -> sy_nlist  . n_un . n_strx ),symbolP -> sy_name_offset,sizeof(symbolP -> sy_nlist  . n_un . n_strx ));
  646.       md_number_to_chars((char *)&(symbolP->sy_nlist.n_desc),symbolP->sy_nlist.n_desc,sizeof(symbolP -> sy_nlist  . n_desc));
  647.       md_number_to_chars((char *)&(symbolP->sy_nlist.n_value),symbolP->sy_nlist.n_value,sizeof(symbolP->sy_nlist.n_value));
  648.       /* symbolP -> sy_nlist  . n_un . n_strx = symbolP -> sy_name_offset; JF replaced by md above */
  649.       if (symbolP -> sy_type == N_UNDF)
  650.       symbolP -> sy_type |= N_EXT; /* Any undefined symbols become N_EXT. */
  651.       append (& next_object_file_charP, (char *)(& symbolP -> sy_nlist),
  652.           (unsigned long)sizeof(struct nlist));
  653.       symbolP -> sy_nlist . n_un . n_name = temp;
  654.     }                /* for each symbol */
  655.  
  656.   /*
  657.    * next_object_file_charP -> slot for next object byte.
  658.    * Emit strings.
  659.    * Find strings by crawling along symbol table chain.
  660.    */
  661. /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
  662.   md_number_to_chars((char *)&string_byte_count, string_byte_count, sizeof(string_byte_count));
  663.  
  664.   append (& next_object_file_charP, (char *)&string_byte_count, (unsigned long)sizeof(string_byte_count));
  665.   for (   symbolP = symbol_rootP;   symbolP;   symbolP = symbolP -> sy_next   )
  666.     {
  667.       if (symbolP -> sy_name)
  668.     {            /* Ordinary case: not .stabd. */
  669.       append (& next_object_file_charP, symbolP -> sy_name,
  670.           (unsigned long)(strlen (symbolP -> sy_name) + 1));
  671.     }
  672.     }                /* for each symbol */
  673.  
  674.   know( next_object_file_charP == the_object_file + size_of_the_object_file );
  675.  
  676.   output_file_append (the_object_file, size_of_the_object_file, out_file_name);
  677.  
  678.   if (flagseen['G'])        /* GDB symbol file to be appended? */
  679.     {
  680.       gdb_emit (out_file_name);
  681.       gdb_end ();
  682.     }
  683.  
  684.   output_file_close (out_file_name);
  685. #else    /* VMS */
  686.   /*
  687.    *    Now do the VMS-dependent part of writing the object file
  688.    */
  689.   VMS_write_object_file(text_siz, data_siz, text_frag_root, data_frag_root);
  690. #endif    /* VMS */
  691. }                /* write_object_file() */
  692.  
  693. /*
  694.  *            relax_segment()
  695.  *
  696.  * Now we have a segment, not a crowd of sub-segments, we can make fr_address
  697.  * values.
  698.  *
  699.  * Relax the frags.
  700.  *
  701.  * After this, all frags in this segment have addresses that are correct
  702.  * within the segment. Since segments live in different file addresses,
  703.  * these frag addresses may not be the same as final object-file addresses.
  704.  */
  705. #ifndef    VMS
  706. static
  707. #endif    /* not VMS */
  708. void
  709. relax_segment (segment_frag_root, segment_type)
  710.      struct frag *    segment_frag_root;
  711.      segT        segment_type; /* N_DATA or N_TEXT */
  712. {
  713.   register struct frag *    fragP;
  714.   register relax_addressT    address;
  715.   /* register relax_addressT    old_address; JF unused */
  716.   /* register relax_addressT    new_address; JF unused */
  717.  
  718.   know( segment_type == SEG_DATA || segment_type == SEG_TEXT );
  719.  
  720.   /* In case md_estimate_size_before_relax() wants to make fixSs. */
  721.   subseg_change (segment_type, 0);
  722.  
  723.   /*
  724.    * For each frag in segment: count and store  (a 1st guess of) fr_address.
  725.    */
  726.   address = 0;
  727.   for ( fragP = segment_frag_root;   fragP;   fragP = fragP -> fr_next )
  728.     {
  729.       fragP -> fr_address = address;
  730.       address += fragP -> fr_fix;
  731.       switch (fragP -> fr_type)
  732.     {
  733.     case rs_fill:
  734.       address += fragP -> fr_offset * fragP -> fr_var;
  735.       break;
  736.  
  737.     case rs_align:
  738.       address += relax_align (address, fragP -> fr_offset);
  739.       break;
  740.  
  741.     case rs_org:
  742.       /*
  743.        * Assume .org is nugatory. It will grow with 1st relax.
  744.        */
  745.       break;
  746.  
  747.     case rs_machine_dependent:
  748.       address += md_estimate_size_before_relax
  749.         (fragP, seg_N_TYPE [(int) segment_type]);
  750.       break;
  751.  
  752. #ifndef WORKING_DOT_WORD
  753.         /* Broken words don't concern us yet */
  754.     case rs_broken_word:
  755.         break;
  756. #endif
  757.  
  758.     default:
  759.       BAD_CASE( fragP -> fr_type );
  760.       break;
  761.     }            /* switch(fr_type) */
  762.     }                /* for each frag in the segment */
  763.  
  764.   /*
  765.    * Do relax().
  766.    */
  767.   {
  768.     register long int    stretch; /* May be any size, 0 or negative. */
  769.                 /* Cumulative number of addresses we have */
  770.                 /* relaxed this pass. */
  771.                 /* We may have relaxed more than one address. */
  772.     register long int stretched;  /* Have we stretched on this pass? */
  773.                   /* This is 'cuz stretch may be zero, when,
  774.                      in fact some piece of code grew, and
  775.                      another shrank.  If a branch instruction
  776.                      doesn't fit anymore, we could be scrod */
  777.  
  778.     do
  779.       {
  780.     stretch = stretched = 0;
  781.     for (fragP = segment_frag_root;  fragP;  fragP = fragP -> fr_next)
  782.       {
  783.         register long int    growth;
  784.         register long int    was_address;
  785.         /* register long int    var; */
  786.         register long int    offset;
  787.         register symbolS *    symbolP;
  788.         register long int    target;
  789.         register long int    after;
  790.         register long int    aim;
  791.  
  792.         was_address = fragP -> fr_address;
  793.         address = fragP -> fr_address += stretch;
  794.         symbolP = fragP -> fr_symbol;
  795.         offset = fragP -> fr_offset;
  796.         /* var = fragP -> fr_var; */
  797.         switch (fragP -> fr_type)
  798.           {
  799.           case rs_fill:    /* .fill never relaxes. */
  800.         growth = 0;
  801.         break;
  802.  
  803. #ifndef WORKING_DOT_WORD
  804.         /* JF:  This is RMS's idea.  I do *NOT* want to be blamed
  805.            for it I do not want to write it.  I do not want to have
  806.            anything to do with it.  This is not the proper way to
  807.            implement this misfeature. */
  808.           case rs_broken_word:
  809.             {
  810.         struct broken_word *lie;
  811.         struct broken_word *untruth;
  812.         extern int md_short_jump_size;
  813.         extern int md_long_jump_size;
  814.  
  815.             /* Yes this is ugly (storing the broken_word pointer
  816.                in the symbol slot).  Still, this whole chunk of
  817.                code is ugly, and I don't feel like doing anything
  818.                about it.  Think of it as stubbornness in action */
  819.         growth=0;
  820.             for(lie=(struct broken_word *)(fragP->fr_symbol);
  821.             lie && lie->dispfrag==fragP;
  822.             lie=lie->next_broken_word) {
  823.  
  824.             if(lie->added)
  825.                 continue;
  826.             offset=  lie->add->sy_frag->fr_address+lie->add->sy_value + lie->addnum -
  827.                 (lie->sub->sy_frag->fr_address+lie->sub->sy_value);
  828.             if(offset<=-32768 || offset>=32767) {
  829.                 if(flagseen['k'])
  830.                     as_warn(".word %s-%s+%ld didn't fit",lie->add->sy_name,lie->sub->sy_name,lie->addnum);
  831.                 lie->added=1;
  832.                 if(fragP->fr_subtype==0) {
  833.                     fragP->fr_subtype++;
  834.                     growth+=md_short_jump_size;
  835.                 }
  836.                 for(untruth=lie->next_broken_word;untruth && untruth->dispfrag==lie->dispfrag;untruth=untruth->next_broken_word)
  837.                     if(untruth->add->sy_frag==lie->add->sy_frag && untruth->add->sy_value==lie->add->sy_value) {
  838.                         untruth->added=2;
  839.                         untruth->use_jump=lie;
  840.                     }
  841.                 growth+=md_long_jump_size;
  842.             }
  843.             }
  844.         }
  845.         break;
  846. #endif
  847.           case rs_align:
  848.         growth = relax_align ((relax_addressT)(address + fragP -> fr_fix), offset)
  849.           - relax_align ((relax_addressT)(was_address +  fragP -> fr_fix), offset);
  850.         break;
  851.  
  852.           case rs_org:
  853.         target = offset;
  854.         if (symbolP)
  855.           {
  856.             know(   ((symbolP -> sy_type & N_TYPE) == N_ABS) || ((symbolP -> sy_type & N_TYPE) == N_DATA) || ((symbolP -> sy_type & N_TYPE) == N_TEXT));
  857.             know( symbolP -> sy_frag );
  858.             know( (symbolP->sy_type&N_TYPE)!=N_ABS || symbolP->sy_frag==&zero_address_frag );
  859.             target +=
  860.               symbolP -> sy_value
  861.             + symbolP -> sy_frag -> fr_address;
  862.           }
  863.         know( fragP -> fr_next );
  864.         after = fragP -> fr_next -> fr_address;
  865.         growth - ((target - after ) > 0) ? (target - after) : 0;
  866.                 /* Growth may be -ve, but variable part */
  867.                 /* of frag cannot have < 0 chars. */
  868.                 /* That is, we can't .org backwards. */
  869.  
  870.         growth -= stretch;    /* This is an absolute growth factor */
  871.         break;
  872.  
  873.           case rs_machine_dependent:
  874.         {
  875.           register relax_typeS *    this_type;
  876.           register relax_typeS *    start_type;
  877.           register relax_substateT    next_state;
  878.           register relax_substateT    this_state;
  879.  
  880.           start_type = this_type
  881.             = md_relax_table + (this_state = fragP -> fr_subtype);
  882.         target = offset;
  883.         if (symbolP)
  884.           {
  885.  know(   ((symbolP -> sy_type & N_TYPE) == N_ABS) || ((symbolP -> sy_type &
  886.  N_TYPE) == N_DATA) || ((symbolP -> sy_type & N_TYPE) == N_TEXT));
  887.             know( symbolP -> sy_frag );
  888.             know( (symbolP->sy_type&N_TYPE)!=N_ABS || symbolP->sy_frag==&zero_address_frag );
  889.             target +=
  890.               symbolP -> sy_value
  891.             + symbolP -> sy_frag -> fr_address;
  892.  
  893.             /* If frag has yet to be reached on this pass,
  894.                assume it will move by STRETCH just as we did.
  895.                If this is not so, it will be because some frag
  896.                between grows, and that will force another pass.  */
  897.  
  898.                    /* JF was just address */
  899.                 /* JF also added isdnrange hack */
  900.                 /* There's gotta be a better/faster/etc way
  901.                    to do this. . . */
  902.             if (symbolP->sy_frag->fr_address > was_address && isdnrange(fragP,symbolP->sy_frag))
  903.               target += stretch;
  904.  
  905.           }
  906.           aim = target - address - fragP -> fr_fix;
  907.           if (aim < 0)
  908.             {
  909.               /* Look backwards. */
  910.               for (next_state = this_type -> rlx_more;  next_state;  )
  911.             {
  912.               if (aim >= this_type -> rlx_backward)
  913.                   next_state = 0;
  914.               else
  915.                 {    /* Grow to next state. */
  916.                   this_type = md_relax_table + (this_state = next_state);
  917.                   next_state = this_type -> rlx_more;
  918.                 }
  919.             }
  920.             }
  921.           else
  922.             {
  923. #ifdef DONTDEF
  924. /* JF these next few lines of code are for the mc68020 which can't handle short
  925.    offsets of zero in branch instructions.  What a kludge! */
  926.  if(aim==0 && this_state==(1<<2+0)) {    /* FOO hard encoded from m.c */
  927.     aim=this_type->rlx_forward+1;    /* Force relaxation into word mode */
  928.  }
  929. #endif
  930. /* JF end of 68020 code */
  931.               /* Look forwards. */
  932.               for (next_state = this_type -> rlx_more;  next_state;  )
  933.             {
  934.               if (aim <= this_type -> rlx_forward)
  935.                   next_state = 0;
  936.               else
  937.                 {    /* Grow to next state. */
  938.                   this_type = md_relax_table + (this_state = next_state);
  939.                   next_state = this_type -> rlx_more;
  940.                 }
  941.             }
  942.             }
  943.           if (growth = this_type -> rlx_length - start_type -> rlx_length)
  944.               fragP -> fr_subtype = this_state;
  945.         }
  946.         break;
  947.  
  948.           default:
  949.         BAD_CASE( fragP -> fr_type );
  950.         break;
  951.           }
  952.         if(growth) {
  953.           stretch += growth;
  954.           stretched++;
  955.         }
  956.       }            /* For each frag in the segment. */
  957.       } while (stretched);    /* Until nothing further to relax. */
  958.   }
  959.  
  960.   /*
  961.    * We now have valid fr_address'es for each frag.
  962.    */
  963.  
  964.   /*
  965.    * All fr_address's are correct, relative to their own segment.
  966.    * We have made all the fixS we will ever make.
  967.    */
  968. }                /* relax_segment() */
  969.  
  970. /*
  971.  * Relax_align. Advance location counter to next address that has 'alignment'
  972.  * lowest order bits all 0s.
  973.  */
  974.  
  975. static relax_addressT        /* How many addresses does the .align take? */
  976. relax_align (address, alignment)
  977.      register relax_addressT    address; /* Address now. */
  978.      register long int        alignment; /* Alignment (binary). */
  979. {
  980.   relax_addressT    mask;
  981.   relax_addressT    new_address;
  982.  
  983.   mask = ~ ( (~0) << alignment );
  984.   new_address = (address + mask) & (~ mask);
  985.   return (new_address - address);
  986. }
  987.  
  988. /*
  989.  *            fixup_segment()
  990.  */
  991. static long int
  992. fixup_segment (fixP, this_segment_type)
  993.      register fixS *    fixP;
  994.      int        this_segment_type; /* N_TYPE bits for segment. */
  995. {
  996.   register long int        seg_reloc_count;
  997.         /* JF these all used to be local to the for loop, but GDB doesn't seem to be able to deal with them there, so I moved them here for a bit. */
  998.       register symbolS *    add_symbolP;
  999.       register symbolS *    sub_symbolP;
  1000.       register long int        add_number;
  1001.       register int        size;
  1002.       register char *        place;
  1003.       register long int        where;
  1004.       register char        pcrel;
  1005.       register fragS *        fragP;
  1006.       register int        add_symbol_N_TYPE;
  1007.  
  1008.  
  1009.   seg_reloc_count = 0;
  1010.   for ( ;  fixP;  fixP = fixP -> fx_next)
  1011.     {
  1012.       fragP       = fixP  -> fx_frag;
  1013.       know( fragP );
  1014.       where      = fixP  -> fx_where;
  1015.       place       = fragP -> fr_literal + where;
  1016.       size      = fixP  -> fx_size;
  1017.       add_symbolP = fixP  -> fx_addsy;
  1018.       sub_symbolP = fixP  -> fx_subsy;
  1019.       add_number  = fixP  -> fx_offset;
  1020.       pcrel      = fixP  -> fx_pcrel;
  1021.       if(add_symbolP)
  1022.     add_symbol_N_TYPE = add_symbolP -> sy_type & N_TYPE;
  1023.       if (sub_symbolP)
  1024.     {
  1025.       if(!add_symbolP)    /* Its just -sym */
  1026.         {
  1027.           if(sub_symbolP->sy_type!=N_ABS)
  1028.             as_warn("Negative of non-absolute symbol %s", sub_symbolP->sy_name);
  1029.           add_number-=sub_symbolP->sy_value;
  1030.         }
  1031.       else if (   ((sub_symbolP -> sy_type ^ add_symbol_N_TYPE) & N_TYPE) == 0
  1032.           && (   add_symbol_N_TYPE == N_DATA
  1033.           || add_symbol_N_TYPE == N_TEXT
  1034.           || add_symbol_N_TYPE == N_BSS
  1035.           || add_symbol_N_TYPE == N_ABS))
  1036.         {
  1037.           /* Difference of 2 symbols from same segment. */
  1038.           /* Can't make difference of 2 undefineds: 'value' means */
  1039.           /* something different for N_UNDF. */
  1040.           add_number += add_symbolP -> sy_value - sub_symbolP -> sy_value;
  1041.           add_symbolP = NULL;
  1042.           fixP -> fx_addsy = NULL;
  1043.         }
  1044.       else
  1045.         {
  1046.           /* Different segments in subtraction. */
  1047.           know( sub_symbolP -> sy_type != (N_ABS | N_EXT))
  1048.         if (sub_symbolP -> sy_type == N_ABS)
  1049.             add_number -= sub_symbolP -> sy_value;
  1050.         else
  1051.           {
  1052.                as_warn("Can't emit reloc {- %s-seg symbol \"%s\"} @@ file address %d.",
  1053.                     seg_name[(int)N_TYPE_seg[sub_symbolP->sy_type&N_TYPE]],
  1054.                     sub_symbolP -> sy_name, fragP -> fr_address + where);
  1055.           }
  1056.         }
  1057.     }
  1058.       if (add_symbolP)
  1059.     {
  1060.       if (add_symbol_N_TYPE == this_segment_type && pcrel)
  1061.         {
  1062.           /*
  1063.            * This fixup was made when the symbol's segment was
  1064.            * SEG_UNKNOWN, but it is now in the local segment.
  1065.            * So we know how to do the address without relocation.
  1066.            */
  1067.           add_number += add_symbolP -> sy_value;
  1068.           add_number -= size + where + fragP -> fr_address;
  1069.           pcrel = 0;    /* Lie. Don't want further pcrel processing. */
  1070.           fixP -> fx_addsy = NULL; /* No relocations please. */
  1071.           /*
  1072.            * It would be nice to check that the address does not overflow.
  1073.            * I didn't do this check because:
  1074.            * +  It is machine dependent in the general case (eg 32032)
  1075.            * +  Compiler output will never need this checking, so why
  1076.            *    slow down the usual case?
  1077.            */
  1078.         }
  1079.       else
  1080.         {
  1081.           switch (add_symbol_N_TYPE)
  1082.         {
  1083.         case N_ABS:
  1084.           add_number += add_symbolP -> sy_value;
  1085.           fixP -> fx_addsy = NULL;
  1086.           add_symbolP = NULL;
  1087.           break;
  1088.           
  1089.         case N_BSS:
  1090.         case N_DATA:
  1091.         case N_TEXT:
  1092.           seg_reloc_count ++;
  1093.           add_number += add_symbolP -> sy_value;
  1094.           break;
  1095.           
  1096.         case N_UNDF:
  1097.           seg_reloc_count ++;
  1098.           break;
  1099.           
  1100.         default:
  1101.           BAD_CASE( add_symbol_N_TYPE );
  1102.           break;
  1103.         }        /* switch on symbol seg */
  1104.         }            /* if not in local seg */
  1105.     }            /* if there was a + symbol */
  1106.       if (pcrel)
  1107.     {
  1108.       add_number -= size + where + fragP -> fr_address;
  1109.       if (add_symbolP == 0)
  1110.         {
  1111.           fixP -> fx_addsy = & abs_symbol;
  1112.           seg_reloc_count ++;
  1113.         }
  1114.     }
  1115.       /* OVE added fx_im_disp for ns32k and others */
  1116.       if (!fixP->fx_bit_fixP) {
  1117.     /* JF I hope this works . . . */
  1118.     if((size==1 && (add_number& ~0xFF)   && (add_number&~0xFF!=(-1&~0xFF))) ||
  1119.        (size==2 && (add_number& ~0xFFFF) && (add_number&~0xFFFF!=(-1&~0xFFFF))))
  1120.       as_warn("Fixup of %d too large for field width of %d",add_number, size);
  1121.  
  1122.     switch (fixP->fx_im_disp) {
  1123.     case 0:
  1124. #ifdef SPARC
  1125.       fixP->fx_addnumber = add_number;
  1126.       md_number_to_imm(place, add_number, size, fixP, this_segment_type);
  1127. #else
  1128.       md_number_to_imm (place, add_number, size);
  1129.       /* OVE: the immediates, like disps, have lsb at lowest address */
  1130. #endif
  1131.       break;
  1132.     case 1:
  1133.       md_number_to_disp (place,
  1134.                  fixP->fx_pcrel ? add_number+fixP->fx_pcrel_adjust:add_number,
  1135.                  size);
  1136.       break;
  1137.     case 2: /* fix requested for .long .word etc */
  1138.       md_number_to_chars (place, add_number, size);
  1139.       break;
  1140.     default:
  1141.       as_fatal("Internal error in write.c in fixup_segment");
  1142.     } /* OVE: maybe one ought to put _imm _disp _chars in one md-func */
  1143.       } else {
  1144.     md_number_to_field (place, add_number, fixP->fx_bit_fixP);
  1145.       }
  1146.     }                /* For each fixS in this segment. */
  1147.   return (seg_reloc_count);
  1148. }                /* fixup_segment() */
  1149.  
  1150.  
  1151. /* The sparc needs its own emit_relocations() */
  1152. #ifndef SPARC
  1153. /*
  1154.  *        emit_relocations()
  1155.  *
  1156.  * Crawl along a fixS chain. Emit the segment's relocations.
  1157.  */
  1158. static void
  1159. emit_relocations (fixP, segment_address_in_file)
  1160.      register fixS *    fixP;    /* Fixup chain for this segment. */
  1161.      relax_addressT    segment_address_in_file;
  1162. {
  1163.   struct relocation_info    ri;
  1164.   register symbolS *        symbolP;
  1165.  
  1166.     /* JF this is for paranoia */
  1167.   bzero((char *)&ri,sizeof(ri));
  1168.   for ( ;  fixP;  fixP = fixP -> fx_next)
  1169.     {
  1170.       if (symbolP = fixP -> fx_addsy)
  1171.     {
  1172.  
  1173. #ifndef hpux
  1174.         /* These two 'cuz of NS32K */
  1175.       ri . r_bsr        = fixP -> fx_bsr;
  1176.       ri . r_disp        = fixP -> fx_im_disp;
  1177. #endif
  1178.  
  1179.       ri . r_length        = nbytes_r_length [fixP -> fx_size];
  1180.       ri . r_pcrel        = fixP -> fx_pcrel;
  1181.       ri . r_address    = fixP -> fx_frag -> fr_address
  1182.         +   fixP -> fx_where
  1183.           - segment_address_in_file;
  1184.       if ((symbolP -> sy_type & N_TYPE) == N_UNDF)
  1185.         {
  1186.           ri . r_extern    = 1;
  1187.           ri . r_symbolnum    = symbolP -> sy_number;
  1188.         }
  1189.       else
  1190.         {
  1191.           ri . r_extern    = 0;
  1192.           ri . r_symbolnum    = symbolP -> sy_type & N_TYPE;
  1193.         }
  1194.  
  1195.       /* 
  1196.         The 68k machines assign bit-fields from higher bits to 
  1197.         lower bits ("left-to-right") within the int.  VAXen assign 
  1198.         bit-fields from lower bits to higher bits ("right-to-left").
  1199.         Both handle multi-byte numbers in their usual fashion
  1200.         (Big-endian and little-endian stuff).
  1201.         Thus we need a machine dependent routine to make
  1202.         sure the structure is written out correctly.  FUN!
  1203.        */
  1204.       md_ri_to_chars((char *) &ri, ri); 
  1205.       append (&next_object_file_charP, (char *)& ri, (unsigned long)sizeof(ri));
  1206.     }
  1207.     }
  1208.  
  1209. }
  1210. #endif
  1211.  
  1212. int
  1213. isdnrange(f1,f2)
  1214. struct frag *f1,*f2;
  1215. {
  1216.     while(f1) {
  1217.         if(f1->fr_next==f2)
  1218.             return 1;
  1219.         f1=f1->fr_next;
  1220.     }
  1221.     return 0;
  1222. }
  1223. /* End: as-write.c */
  1224. @
  1225.